<template>
	<view class="home">
		<swiper indicator-dots circular autoplay interval="3000" indicator-color="#000" indicator-active-color="#fff">
			<!--
				indicator-dots:小圆点
				indicator-color:小圆点默认颜色，
				indicator-active-color：选中颜色
				circular:循环滑动
				autoplay:自动切换
				interval：切换间隔 5000
				duration：滑动动画时长 默认500
				
			  -->
			<swiper-item  v-for="item in swipers" :key="item.id"> 
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<!-- 产品列表 -->
				<goodsList :goods="goods" @goodsItemClick="goGoodsDetail"></goodsList>
				
		</view>
		
	</view>
</template>

<script>
	import goodsList from "../../components/goods-list/goods-list.vue"
	export default {
		data() {
			return {
				title: 'Hello',
				swipers:[],
				goods:[],
				navs:[
					{
						path:"/pages/goods/goods",
						icon:"iconfont icon-ziyuan",
						title:"商品列表"
					},
					{
						path:"/pages/contact/contact",
						icon:"iconfont icon-guanyuwomen",
						title:"联系我们"
					},
					{
						path:"/pages/pics/pics",
						icon:"iconfont icon-tupian",
						title:"社区图片"
					},
					{
						path:"/pages/video/video",
						icon:"iconfont icon-shipin",
						title:"学习视频"
					}
				]
			}
		},
		onLoad() {
			
			this.getSwipers();
			this.getHotGoods();
		},
		components:{
			goodsList
		},
		methods: {
			//获取轮播图的数据
			async getSwipers(){
				const res=await this.$myRequest({//this.$myRequest封装的请求函数
					url:"/api/getlunbo"
				})
				//console.log(res)
				this.swipers=res.data.message
			},
			//获取热门商品列表数据
			async getHotGoods(){
				const res=await this.$myRequest({//this.$myRequest封装的请求函数
					url:"/api/getgoods?pageindex=1"
				})
				console.log(res)
				this.goods=res.data.message
			},
			navItemClick(url){
				console.log(url)
				uni.navigateTo({
					url
				})
			},
			goGoodsDetail(id){
				console.log(id);
				uni.navigateTo({
					url:"/pages/goods-detail/goods-detail?id="+id,
				})
			}
		}
	}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.nav{
			display: flex;
			.nav_item{
				// width: 25%;
				flex: 1;
				text-align: center;
				view{
					width: 120rpx;
					height: 120rpx;
					background-color: $shop-color;
					border-radius: 60rpx;
					margin: 20rpx auto;
					line-height: 120rpx;
					color: #fff;
					font-size: 50rpx;
				}
				.icon-tupian{
					font-size: 43rpx;
				}
				text{
					font-size: 29rpx;
				}
			}
		}
		.hot_goods{
			background-color: #eee;
			overflow: hidden;
			margin-top: 30rpx;
			.tit{
				height: 100rpx;
				line-height:100rpx;
				color: $shop-color;
				text-align: center;
				letter-spacing: 40rpx;
				background-color: #fff;
				margin: 6rpx 0;
				font-size: 37rpx;
				font-weight: 550;
			}
		}
	}
	
	
</style>
